package com.hex.liyue.launchdatemodule.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hex.liyue.R;
import com.hex.liyue.commonmodule.utils.L;

import java.util.List;

/**
 * Created by WJ on 2016/6/12.
 */
public class AdapterSelectWant extends BaseAdapter {
    private List<String> lists;
    private LayoutInflater inflater;
    private Context context;

    public AdapterSelectWant(Context context, List<String> lists) {
        this.context = context;
        this.lists = lists;
        inflater = LayoutInflater.from(context);
    }

    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final MyHolder vHolder;
        if (convertView == null) {
            vHolder = new MyHolder();
            convertView = inflater.inflate(R.layout.item_select_want, null);

            vHolder.tv_select_want = (TextView) convertView.findViewById(R.id.tv_select_want);
            convertView.setTag(vHolder);
        } else {
            vHolder = (MyHolder) convertView.getTag();
        }
        L.e("lists[position]", lists.get(position));
        vHolder.tv_select_want.setText(lists.get(position));
        vHolder.tv_select_want.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                L.e("position", position + "");
                onItemClickListener.onItemClickListener(position);
            }
        });

        return convertView;
    }

    public interface OnItemClickListener {
        void onItemClickListener(int position);

    }

    public static class MyHolder {
        public TextView tv_select_want;
    }
}
